home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD2001.psc / My Projects / HTTPServer / V2.0 / HTTPHeaderList.cls < prev    next >
Encoding:
Visual Basic class definition  |  1999-04-29  |  3.0 KB  |  121 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "HTTPHeaderList"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = False
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = True
  14. Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
  15. Attribute VB_Ext_KEY = "Collection" ,"HTTPParameter"
  16. Attribute VB_Ext_KEY = "Member0" ,"HTTPParameter"
  17. Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
  18. Option Explicit
  19.  
  20. 'local variable to hold collection
  21. Private mCol As Collection
  22. Public Function AddItems(Request As String, Optional NewCol As Boolean = False) As Boolean
  23.  
  24.   Dim col As Collection
  25.   Dim objNew As HTTPHeader
  26.   Dim iLoop As Long
  27.   
  28.   On Error GoTo AddItemsError
  29.   
  30.   If NewCol Then
  31.     Set mCol = New Collection
  32.   End If
  33.   Set col = HeaderDecode(Request)
  34.   
  35.   For iLoop = 1 To col.Count
  36.     Set objNew = New HTTPHeader
  37.     If objNew.Initialize(col(iLoop)) = False Then
  38.       'Debug.Assert False
  39.       Exit Function
  40.     End If
  41.     mCol.Add objNew
  42.     Set objNew = Nothing
  43.   Next iLoop
  44.   
  45.   AddItems = True
  46.   
  47. AddItemsError:
  48.   Debug.Assert Err.Number = 0
  49.  
  50. End Function
  51.  
  52. Public Property Get Item(vntIndexKey As Variant) As HTTPHeader
  53. Attribute Item.VB_UserMemId = 0
  54.     'used when referencing an element in the collection
  55.     'vntIndexKey contains either the Index or Key to the collection,
  56.     'this is why it is declared as a Variant
  57.     'Syntax: Set foo = x.Item(xyz) or Set foo = x.Item(5)
  58.   Set Item = mCol(vntIndexKey)
  59. End Property
  60.  
  61. Public Property Get Count() As Long
  62.     'used when retrieving the number of elements in the
  63.     'collection. Syntax: Debug.Print x.Count
  64.     Count = mCol.Count
  65. End Property
  66.  
  67.  
  68. Public Property Get NewEnum() As IUnknown
  69. Attribute NewEnum.VB_UserMemId = -4
  70. Attribute NewEnum.VB_MemberFlags = "40"
  71.     'this property allows you to enumerate
  72.     'this collection with the For...Each syntax
  73.     Set NewEnum = mCol.[_NewEnum]
  74. End Property
  75.  
  76.  
  77. Public Function Values(Key As String) As Variant
  78.  
  79.   Dim col As Collection
  80.   Dim RetVal As String
  81.   Dim CurVal As String
  82.   Dim iCount As Long
  83.   Dim iLoop As Long
  84.   
  85.   For iLoop = 1 To mCol.Count
  86.     If StrComp(mCol(iLoop).Name, Key, vbTextCompare) = 0 Then
  87.       CurVal = mCol(iLoop).Value
  88.       iCount = iCount + 1
  89.       Select Case iCount
  90.         Case 1
  91.           RetVal = CurVal
  92.           
  93.         Case 2
  94.           Set col = New Collection
  95.           col.Add RetVal
  96.           col.Add CurVal
  97.           
  98.         Case Else
  99.           col.Add CurVal
  100.       End Select
  101.     End If
  102.   Next iLoop
  103.   
  104.   If iCount > 1 Then
  105.     Set Values = col
  106.     Set col = Nothing
  107.   Else
  108.     Values = RetVal
  109.   End If
  110.  
  111. End Function
  112. Private Sub Class_Initialize()
  113.     'creates the collection when this class is created
  114.     Set mCol = New Collection
  115. End Sub
  116. Private Sub Class_Terminate()
  117.     'destroys collection when this class is terminated
  118.     Set mCol = Nothing
  119. End Sub
  120.  
  121.